package com.qf.listener;

import com.event.EventListener;
import com.qf.entity.R;
import com.qf.entity.Room;
import com.qf.entity.RoomPrice;
import com.qf.feign.RoomFeign;
import com.qf.service.ISearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class PriceEventListener implements EventListener<RoomPrice> {
    @Autowired
    private ISearchService searchService;
    @Autowired
    private RoomFeign roomFeign;
    @Override
    public String eventType() {
        return "price_update";
    }

    @Override
    public void eventHandler(RoomPrice roomPrice) {
        System.out.println("搜索服务接收房间价格的消息：" + roomPrice);
        R<Room> room = roomFeign.getRoomById(roomPrice.getRid());
        searchService.updateRoomPrice(room.getData().getHid(),roomPrice);
    }
}
